<?php

class CateAction extends Action {
	
	
	//初始化
	public function _initialize() {
		//加载分类导航
		$cate = D('Cate');
    	$list = $cate->loadCateList();
    	$this->assign('cateList',$list);	
	}

    
    //加载分类列表
    public function loadCateList() {
    	$pid = $_REQUEST['pid'];
    	$cate = D('Cate');
    	$list = $cate->loadCateList($pid);
    	$this->assign('childCateList',$list);
    	$this->display('edit');
    }


	
	
	//转到添加
	public function add() {
		$this->assign('action',U('Cate/doAdd'));
    	$this->display();
	}
	
	//添加
	public function doAdd() {
		$cate = M('Cate');
		$cate->create();
		if($cate->add()) {
			$this->redirect(U('Cate/edit'));
		} else {
			echo 'no';
		}
	}
	
	//转到编辑
	public function edit() {
		$id = $_REQUEST['id'];
		$cate = D('Cate');
		
		$obj = $cate->where('id='.$id)->find();
		
		//print_r($cate);
		$this->assign('action',U('Cate/doEditCate'));
		$this->assign('obj',$obj);
		$this->display();
	}
	
	//编辑
	public function doEdit() {
		$cate = D('Cate');
		$cate->create();
		if($cate->save()) {
			$this->redirect(U('Cate/edit'));
		} else {
			echo 'no';
		}
	}
	
	//删除
	public function del() {}
	
}

?>